import 'package:flutter/material.dart';
import 'package:interview/components/app/app_ripple_button.dart';
import 'package:interview/components/app/app_spread_icon.dart';
import 'package:interview/components/tag.dart';
import 'package:interview/config/app.enum.dart';
import 'package:interview/theme/app_colors.dart';

class QuestionUserinfo extends StatelessWidget {
  final String avatar;
  final String username;
  final String questionStem;
  final AppColors theme;
  final int difficulty;
  final int collectFlag;
  final void Function(BuildContext context, AppColors theme) onTap;
  final void Function(TapDownDetails details) onTapDown;
  final void Function(String type) onChangeCollect;

  const QuestionUserinfo({
    required this.avatar,
    required this.username,
    required this.questionStem,
    required this.theme,
    required this.difficulty,
    required this.onTap,
    required this.onTapDown, 
    required this.collectFlag,
    required this.onChangeCollect,
    Key? key, 
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final hasAvatar = avatar.isEmpty;
    final avatarWidget = hasAvatar
        ? Image.asset('assets/default_avatar.png', width: 56, height: 56)
        : CircleAvatar(radius: 24, backgroundImage: NetworkImage(avatar));

    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        SizedBox(
          width: double.infinity,
          child:Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Row(
                children: [
                  avatarWidget,
                  const SizedBox(width: 8),
                  Text(username.isEmpty ? "未知用户" : username,style: TextStyle(fontSize: 13, color: theme.contrastMix3, fontWeight: FontWeight.w500)),
                ],
              ),
              AppSpreadIcon(
                path: "${AppEnumAssets.basePath}collect.svg",
                flag: collectFlag,
                flagColor:const Color(0xffff4ea2a) ,
                noFlagColor: const Color.fromARGB(255, 221, 221, 221),
                size: 24,
                onTap: () => onChangeCollect("collect"),
              )
            ],
          ), 
        ),
        SizedBox(height: 8,),
        Text("$questionStem", style: TextStyle(fontSize: 14, color: theme.contrastPure, fontWeight: FontWeight.bold)),
        SizedBox(height: 8,),
        SizedBox(
          width: double.infinity,
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisSize: MainAxisSize.min,
            children: [
              Tag(difficulty: difficulty),
              Container(
                width: 24,
                height: 24,
                decoration: BoxDecoration(color: Colors.transparent),
                child: AppRippleButton(
                  onTap: () => onTap(context, theme),
                  onTapDown: (details) => onTapDown(details),
                  borderRadius: BorderRadius.circular(12),
                  splashColor: theme.contrastMix3!.withOpacity(0.2),
                  highlightColor: theme.contrastMix3!.withOpacity(0.2),
                  child: Center(child: Image.asset("${AppEnumAssets.basePath}ic_home_more.png", width: 14, height: 14)),
                ),
              ),
            ],
          ),
        ),
        SizedBox(height: 14),
        Container(height: 8, decoration: BoxDecoration(color: theme.subjectMix2, borderRadius: BorderRadius.circular(2))),
      ],
    );
    
  }
}


